package org.chen.controller;

import lombok.extern.slf4j.Slf4j;
import org.chen.domain.dto.VoiceQueryDTO;
import org.chen.domain.entity.VideoVoice;
import org.chen.domain.response.PageResult;
import org.chen.domain.response.Result;
import org.chen.domain.vo.VoiceVO;
import org.chen.service.VoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/video/voice")
@Slf4j
public class VoiceController {
    
    @Autowired
    private VoiceService voiceService;
    
    /**
     * 获取语音列表（支持分类查询）
     */
    @GetMapping("/list")
    public Result<PageResult<VoiceVO>> getVoiceList(
            VoiceQueryDTO voiceQueryDTO) {
        try {
            PageResult<VoiceVO> voices = voiceService.getVoiceList(voiceQueryDTO);
            return Result.success(voices);
        } catch (Exception e) {
            log.error("Get voice list failed", e);
            return Result.error(e.getMessage());
        }
    }
    
    /**
     * 获取语音分类统计
     */
    @GetMapping("/stats")
    public Result<Map<String, Map<String, Map<String, Long>>>> getVoiceStats() {
        try {
            Map<String, Map<String, Map<String, Long>>> stats = voiceService.getVoiceStats();
            return Result.success(stats);
        } catch (Exception e) {
            log.error("Get voice stats failed", e);
            return Result.error(e.getMessage());
        }
    }

    /**
     * 获取语音数据
     */
    @GetMapping("/{id}")
    public Result<VideoVoice> getVoiceById(@PathVariable String id) {
        try {
            VideoVoice voice = voiceService.getVoiceById(id);
            return Result.success(voice);
        } catch (Exception e) {
            log.error("Get voice failed", e);
            return Result.error(e.getMessage());
        }
    }
}